<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico" >
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/static/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/static/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/static/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/style.css"/>   <#-- 自己的样式css -->
    <!--[if IE 6]>
    <script type="text/javascript" src="/static/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>回收站</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span>
    管理员管理 <span class="c-gray en">&gt;</span> 管理员列表
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>
<div class="page-container">
    <div class="text-c"> 日期范围：
        <input type="text" id="datemin" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" class="input-text Wdate" style="width:140px;">
        -
        <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:140px;">
        <input type="text" class="input-text" style="width:250px" placeholder="输入管理员名称" id="adminName" name="">
        <button type="submit" class="btn btn-success" id="submitBtn" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l"><a href="javascript:;" id="admin_dels" class="btn btn-danger radius">
            <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
        </a>
        </span>
    </div>
    <table id="layAdmin_table" lay-filter="table"></table>
    <script type="text/html" id="tableBar">
        <a class="layui-btn layui-btn-warm layui-btn-xs" id="admin_stop" lay-event="open">恢复</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" id="admin_del" lay-event="del">删除</a>
    </script>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/static/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/static/layui/layui.js"></script>
<script type="text/javascript" src="/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="/static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript">
    layui.use(['table','layer'], function(){
        var table = layui.table;
        var $ = layui.jquery;
        var layer = layui.layer;

        var tableIns = table.render({
            elem:"#layAdmin_table",
            url:"/dba/recycle_list",
            page:true,
            request:{
                pageName:"pageNum",
                limitName:"pageSize"
            },
            cols:[[
                {type:'checkbox'},
                {field: 'aId', title: 'ID',align:"center",sort: true, width:70},
                {field: 'aUsername', title: '用户名', width:110},
                {field: 'aName', title: '真实姓名', width:90},
                {field: 'role', title: '角色', width:100},
                {field: 'aCreateTime', title: '创建时间',sort:true, width:180},
                {field: 'aUpdateTime', title: '更新时间',sort:true, width:180},
                {field: 'state', title: '是否已启用', width:100},    //做样式
                {field: 'deleted', title: '删除状态', width:100},    //做样式
                {title:'操作',toolbar:'#tableBar'}
            ]],
        });

        table.on('tool(table)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent === 'open'){
                layer.confirm('确认要恢复吗？',function(indexCon){
                    var id = data["aId"];
                    var deleted;
                    if (layEvent === "open"){
                        deleted = 0 ;
                    }
                    // 改变表中的deleted字段
                    $.ajax({
                        type:"POST",
                        url:"/dba/admin_open", // /dba/admin_open
                        dataType:"json",
                        traditional:true,
                        data:{"id":id,"deleted":deleted},
                        success:function(data){
                            //恢复成功后，重载table
                            console.log(data);
                            if (data.ret === true){
                                layer.alert("恢复成功!",{icon:1},function(index,obj){
                                    tableIns.reload({
                                        url:"/dba/recycle_list"
                                    });
                                    layer.close(index);
                                });
                                layer.close(indexCon);
                            }else if (data.ret === false){
                                layer.open({
                                    title:"错误",
                                    content:data.msg,
                                    icon:2,
                                    yes:function(index,obj){
                                        layer.close(index);
                                    },
                                });
                                layer.close(indexCon);
                            }
                        },
                        error:function(data){
                            console.log(data);
                            layer.open({
                                title:"异常",
                                icon:2,
                                content:"服务器异常!",
                                yes:function(index,obj){
                                    layer.close(index);
                                }
                            });
                            layer.close(indexCon);
                        },
                    });
                });
            }if(layEvent === 'del'){
                layer.confirm('确认要删除吗？',function(indexCon){
                    var jsonId = {"id":data["aId"]};
                    $.ajax({
                        type:"POST",
                        url:"/dba/del",
                        dataType:"json",
                        data:jsonId,
                        success:function(data){
                            console.log(data);
                            if (data.ret === true){
                                layui.alert("删除成功!",{icon:1},function(index,obj){
                                    layer.close(index);
                                });
                                layer.close(indexCon);
                            }else if (data.ret === false){
                                layui.alert("删除失败!",{icon:2},function(index,obj){
                                    layer.close(index);
                                });
                                layer.close(indexCon);
                            }
                        },
                        error:function(data){
                            layer.open({
                                title:"异常",
                                icon:2,
                                content:"服务器异常!",
                                yes:function(index,obj){
                                    layer.close(index);
                                }
                            });
                            layer.close(indexCon);
                        },
                    });
                }
            }
        };

        var dateMin = $("#datemin").val();
        var dateMax = $("#datemax").val();
        var adminName = $("#adminName").val();
        console.log(dateMin);
        console.log(dateMax);
        console.log(adminName);
        /*$("#submitBtn").click(function(){

        });*/
    };
    /*

        $("#submitBtn").click(function(){
            var dateMin = $("#datemin").val();
            var dateMax = $("#datemax").val();
            var adminName = $("#adminName").val();
            var conditionJso = "" ;
            if (dateMin == "" && dateMax == "" && adminName.trim() == ""){
                tableIns.reload({
                    url:"/dba/admin_list"
                });
                return ;
            }

            if(adminName.trim() != "" && dateMin == "" && dateMax == ""){
                conditionJso = {"adminName":adminName.trim()};
                tableIns.reload({
                    url:"/dba/condition_query",
                    where:conditionJso
                });
            }

            if(adminName.trim() == "" && dateMin != "" && dateMax != ""){
                conditionJso = {"dateMin":dateMin,"dateMax":dateMax};
                tableIns.reload({
                    url:"/dba/condition_query",
                    where:conditionJso
                });
            }

            if(dateMin != "" && dateMax != "" && adminName.trim() != ""){
                conditionJso = {"dateMin":dateMin,"dateMax":dateMax,"adminName":adminName.trim()};
                tableIns.reload({
                    url:"/dba/condition_query",
                    where:conditionJso
                });

            }
        });

        /!* 监听复选框 *!/
        /!* 删除多个 *!/
        var idArray = new Array();
        table.on("checkbox(table)",function(obj){
            var data = obj.data ;
            var checkStatus = obj.checked; //true || false
            var checkType = obj.type ; // one || all
            if (checkStatus){   //已经被选择状态
                var id = data["aId"];
                idArray.push(id);
            }
        });
        $("#admin_dels").click(function(obj){
            layer.confirm("确认删除吗?",function(index){
                var idArrayJson = {"id":idArray,"del":1};
                $.ajax({
                    type: 'POST',
                    url: '/dba/admin_delete',
                    dataType:"json",
                    traditional:true,
                    data:idArrayJson,
                    success: function(data){
                        idArray.slice(0,idArray.length);
                        console.log(data.msg);
                        if(data.msg === '不可删除'){
                            layer.msg("您不可以删除这条记录");
                        }
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                        layer.close(index);
                        tableIns.reload({
                            url:"/dba/admin_list"
                        });
                    },
                    error:function(data) {
                        idArray.slice(0,idArray.length);
                        console.log(data.msg);
                        layer.close(index);
                    },
                });
            });
        });
    });*/

    /*$.ajax({
                type:"GET",
                url:"/dba/condition_query",
                contentType:"json",
                dataType:"json",
                data:conditionJso,
                success:function(data){
                    console.log(data);
                },
                error:function(data){
                    console.log(data);
                }
            });*/
    /*
        参数解释：
        title	标题
        url		请求的url
        id		需要操作的数据id
        w		弹出层宽度（缺省调默认值）
        h		弹出层高度（缺省调默认值）
    */
</script>
</body>
</html>